from flask import Flask
from app.config import config
from app.extensions import config_extensions
from app.apis import config_resource
from app import models


# 使用工厂函数创建app
def create_app(config_name='default'):
    # 创建对象
    app = Flask(__name__)

    # 初始化配置(通过类)
    if config_name not in config:
        config_name = 'default'
    app.config.from_object(config[config_name])

    # 配置扩展
    config_extensions(app)

    # 配置资源
    config_resource(app)

    # 返回对象
    return app
